package io.renren.modules.common.controller;

import java.util.*;
import java.util.Map;

import io.renren.modules.common.viewdo.SelectOption;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.common.entity.WelfareEntity;
import io.renren.modules.common.service.WelfareService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author nyc
 * @email 2691778746@qq.com
 * @date 2022-03-09 12:39:27
 */
@RestController
@RequestMapping("common/welfare")
public class WelfareController {
    @Autowired
    private WelfareService welfareService;

    @GetMapping("/select-option")
    public R selectOption(){
        List<SelectOption> listData = welfareService.selectOptionWelfare();
        return R.ok().put("data",listData);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("common:welfare:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = welfareService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("common:welfare:info")
    public R info(@PathVariable("id") Integer id){
		WelfareEntity welfare = welfareService.getById(id);

        return R.ok().put("welfare", welfare);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("common:welfare:save")
    public R save(@RequestBody WelfareEntity welfare){
		welfareService.save(welfare);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("common:welfare:update")
    public R update(@RequestBody WelfareEntity welfare){
		welfareService.updateById(welfare);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("common:welfare:delete")
    public R delete(@RequestBody Integer[] ids){
		welfareService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
